import time
from multiprocessing import Process
from threading import Thread

# 利用Python实现一个多线程程序
# 将多线程程序改为多进程程序


# 定义打印时间
def ptime():
    pt = time.time()
    time.sleep(0.5)
    print(pt)

# 多线程打印时间


if __name__ == "__main__":
    start_time = time.time()
    for i in range(25):
        t = Thread(target=ptime)
        t.start()
    print("done")
    end_time = time.time()
    print(f"多线程运行时间为：{end_time - start_time} 秒")

# 多进程打印时间
if __name__ == "__main__":
    start_time = time.time()
    for i in range(25):
        p = Process(target=ptime)
        p.start()
    print("done!!!")
    end_time = time.time()
    print(f"多进程运行时间为：{end_time - start_time} 秒")


